<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="com.tpix.PixieCore" %>
<%@ page import="java.util.*" %>
<%@ page import="com.tpix.photo.Photo" %>
<%@ page import="com.google.appengine.api.datastore.Key" %>
<%@ page import="com.google.appengine.api.datastore.KeyFactory" %>	

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<!-- get GET data for tag and album requests -->
	<%
		String kind = request.getParameter("kind"); 		// eg. /detail.jsp?key=123keyxyz
		String idString = request.getParameter("id"); 		// eg. /detail.jsp?key=123keyxyz
	%>

	<!-- Get references to Java objects -->
	<%  PixieCore core = (PixieCore) request.getSession().getAttribute("core");
		if (core == null) {
			core = new PixieCore();
			request.getSession().setAttribute("core", core);
		}
		// convert id from String to long
		long id = Long.parseLong(idString.trim());
		// get Key using kind and id from GET data
		Key key = KeyFactory.createKey(kind, id);
		// get image URL from Key
		String URL = core.URLfromKey(key);
		// get photo from Key
		Photo photo = core.photoFromKey(key);
		%>
	<!-- Put key into request data for servlet -->
	<%
		request.getSession().setAttribute("kind",kind);
		request.getSession().setAttribute("idString", idString);
		%>
	<%-- Detect User Logged In --%>
	<%  if (!core.loggedIn()) {
			// user is not logged in. Redirect to login page
			response.sendRedirect("/login.jsp");
		}
		%>

	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Pixie - Edit</title>
	
	<link type="text/css" rel="stylesheet" href="/stylesheets/edit_photo.css" />
	<link type="text/css" rel="stylesheet" href="/stylesheets/960.css" />
	
	<!-- 	TypeKit -->
	<script type="text/javascript" src="http://use.typekit.com/waa6dbj.js"></script>
	<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
	
</head>

<body>

<div class="container_12">
	<div id="wrapper">
	
	<div class="grid_3 push_1">
		<h3>    </h3><br>
	</div>
	<div class="clear"></div>

	<div class="grid_6 push_1">
		<div class="image_preview">
			<a href="<%= URL %>"><img src="<%= URL+"=s300" %>"/></a>			
		</div>
	</div>

	<div class="grid_4 push_1">
	<FORM action="detailsservlet" method="post">		
			
				<p>
				<strong>Title:</strong><br> <%= photo.getTitle() %>
				</p>
				<p>
				<strong>Caption:</strong><br> <%= photo.getCaption() %>
				</p>
				<p>
				<strong>Description:</strong><br> <%= photo.getDescription() %>
				</p>
				<p>
				<strong>Album: </strong> <%= photo.getAlbumName() %>
				</p> 
				<input	type="submit" name="action" value="Delete">
				<input	type="submit" name="action" value="Main Page">
	
	</form>
	</div>	
	</div>

</div>
</body>
</html>